package com.example.demo.controller;

import com.example.demo.model.Notification;
import com.example.demo.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notify")
public class NotificationController {
    @Autowired
    NotificationService service;

    @PostMapping("/send")
    public String send(@RequestParam Long userId,
                       @RequestParam String title,
                       @RequestParam String content,
                       @RequestParam String type,
                       @RequestParam String email) {
        service.sendNotification(userId, title, content, type, email);
        return "通知发送成功";
    }

    @GetMapping("/list")
    public List<Notification> list(@RequestParam Long userId) {
        return service.repo.findByUserId(userId);
    }
}